package generalpattern.diagram.providers;

import generalpattern.diagram.edit.parts.ComponentName2EditPart;
import generalpattern.diagram.edit.parts.ComponentName3EditPart;
import generalpattern.diagram.edit.parts.ComponentNameEditPart;
import generalpattern.diagram.edit.parts.ConnectorName2EditPart;
import generalpattern.diagram.edit.parts.ConnectorName3EditPart;
import generalpattern.diagram.edit.parts.ConnectorNameEditPart;
import generalpattern.diagram.edit.parts.ConstraintNameEditPart;
import generalpattern.diagram.edit.parts.PatternName2EditPart;
import generalpattern.diagram.edit.parts.PatternName3EditPart;
import generalpattern.diagram.edit.parts.PatternNameEditPart;
import generalpattern.diagram.edit.parts.RoleName2EditPart;
import generalpattern.diagram.edit.parts.RoleNameEditPart;
import generalpattern.diagram.parsers.MessageFormatParser;
import generalpattern.diagram.part.GeneralPatternMetamodelVisualIDRegistry;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
import org.eclipse.gmf.runtime.notation.View;

/**
 * @generated
 */
public class GeneralPatternMetamodelParserProvider extends AbstractProvider
		implements IParserProvider {

	/**
	 * @generated
	 */
	private IParser patternName_5051Parser;

	/**
	 * @generated
	 */
	private IParser getPatternName_5051Parser() {
		if (patternName_5051Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			patternName_5051Parser = parser;
		}
		return patternName_5051Parser;
	}

	/**
	 * @generated
	 */
	private IParser componentName_5052Parser;

	/**
	 * @generated
	 */
	private IParser getComponentName_5052Parser() {
		if (componentName_5052Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			componentName_5052Parser = parser;
		}
		return componentName_5052Parser;
	}

	/**
	 * @generated
	 */
	private IParser connectorName_5053Parser;

	/**
	 * @generated
	 */
	private IParser getConnectorName_5053Parser() {
		if (connectorName_5053Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			connectorName_5053Parser = parser;
		}
		return connectorName_5053Parser;
	}

	/**
	 * @generated
	 */
	private IParser roleName_5054Parser;

	/**
	 * @generated
	 */
	private IParser getRoleName_5054Parser() {
		if (roleName_5054Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getRole_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			roleName_5054Parser = parser;
		}
		return roleName_5054Parser;
	}

	/**
	 * @generated
	 */
	private IParser roleName_5042Parser;

	/**
	 * @generated
	 */
	private IParser getRoleName_5042Parser() {
		if (roleName_5042Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getRole_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			roleName_5042Parser = parser;
		}
		return roleName_5042Parser;
	}

	/**
	 * @generated
	 */
	private IParser constraintName_5041Parser;

	/**
	 * @generated
	 */
	private IParser getConstraintName_5041Parser() {
		if (constraintName_5041Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getConstraint_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			constraintName_5041Parser = parser;
		}
		return constraintName_5041Parser;
	}

	/**
	 * @generated
	 */
	private IParser componentName_5050Parser;

	/**
	 * @generated
	 */
	private IParser getComponentName_5050Parser() {
		if (componentName_5050Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			componentName_5050Parser = parser;
		}
		return componentName_5050Parser;
	}

	/**
	 * @generated
	 */
	private IParser componentName_5049Parser;

	/**
	 * @generated
	 */
	private IParser getComponentName_5049Parser() {
		if (componentName_5049Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			componentName_5049Parser = parser;
		}
		return componentName_5049Parser;
	}

	/**
	 * @generated
	 */
	private IParser connectorName_5048Parser;

	/**
	 * @generated
	 */
	private IParser getConnectorName_5048Parser() {
		if (connectorName_5048Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			connectorName_5048Parser = parser;
		}
		return connectorName_5048Parser;
	}

	/**
	 * @generated
	 */
	private IParser patternName_5047Parser;

	/**
	 * @generated
	 */
	private IParser getPatternName_5047Parser() {
		if (patternName_5047Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			patternName_5047Parser = parser;
		}
		return patternName_5047Parser;
	}

	/**
	 * @generated
	 */
	private IParser connectorName_5045Parser;

	/**
	 * @generated
	 */
	private IParser getConnectorName_5045Parser() {
		if (connectorName_5045Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			connectorName_5045Parser = parser;
		}
		return connectorName_5045Parser;
	}

	/**
	 * @generated
	 */
	private IParser patternName_5046Parser;

	/**
	 * @generated
	 */
	private IParser getPatternName_5046Parser() {
		if (patternName_5046Parser == null) {
			EAttribute[] features = new EAttribute[] { org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			patternName_5046Parser = parser;
		}
		return patternName_5046Parser;
	}

	/**
	 * @generated
	 */
	protected IParser getParser(int visualID) {
		switch (visualID) {
		case PatternNameEditPart.VISUAL_ID:
			return getPatternName_5051Parser();
		case ComponentNameEditPart.VISUAL_ID:
			return getComponentName_5052Parser();
		case ConnectorNameEditPart.VISUAL_ID:
			return getConnectorName_5053Parser();
		case RoleName2EditPart.VISUAL_ID:
			return getRoleName_5054Parser();
		case RoleNameEditPart.VISUAL_ID:
			return getRoleName_5042Parser();
		case ConstraintNameEditPart.VISUAL_ID:
			return getConstraintName_5041Parser();
		case ComponentName2EditPart.VISUAL_ID:
			return getComponentName_5050Parser();
		case ComponentName3EditPart.VISUAL_ID:
			return getComponentName_5049Parser();
		case ConnectorName2EditPart.VISUAL_ID:
			return getConnectorName_5048Parser();
		case PatternName2EditPart.VISUAL_ID:
			return getPatternName_5047Parser();
		case ConnectorName3EditPart.VISUAL_ID:
			return getConnectorName_5045Parser();
		case PatternName3EditPart.VISUAL_ID:
			return getPatternName_5046Parser();
		}
		return null;
	}

	/**
	 * Utility method that consults ParserService
	 * @generated
	 */
	public static IParser getParser(IElementType type, EObject object,
			String parserHint) {
		return ParserService.getInstance().getParser(
				new HintAdapter(type, object, parserHint));
	}

	/**
	 * @generated
	 */
	public IParser getParser(IAdaptable hint) {
		String vid = (String) hint.getAdapter(String.class);
		if (vid != null) {
			return getParser(GeneralPatternMetamodelVisualIDRegistry
					.getVisualID(vid));
		}
		View view = (View) hint.getAdapter(View.class);
		if (view != null) {
			return getParser(GeneralPatternMetamodelVisualIDRegistry
					.getVisualID(view));
		}
		return null;
	}

	/**
	 * @generated
	 */
	public boolean provides(IOperation operation) {
		if (operation instanceof GetParserOperation) {
			IAdaptable hint = ((GetParserOperation) operation).getHint();
			if (GeneralPatternMetamodelElementTypes.getElement(hint) == null) {
				return false;
			}
			return getParser(hint) != null;
		}
		return false;
	}

	/**
	 * @generated
	 */
	private static class HintAdapter extends ParserHintAdapter {

		/**
		 * @generated
		 */
		private final IElementType elementType;

		/**
		 * @generated
		 */
		public HintAdapter(IElementType type, EObject object, String parserHint) {
			super(object, parserHint);
			assert type != null;
			elementType = type;
		}

		/**
		 * @generated
		 */
		public Object getAdapter(Class adapter) {
			if (IElementType.class.equals(adapter)) {
				return elementType;
			}
			return super.getAdapter(adapter);
		}
	}

}
